package com.googlecode.marrowboy.assertionresult;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Holds details of test classes in {@link ClassDetail} objects, and reporting
 * methods for counting different kinds of assertions.
 * 
 * @author mjg
 */
public class TestRunDetail {

	private final Map<String, ClassDetail> classResults;

	public TestRunDetail() {
		classResults = new LinkedHashMap<String, ClassDetail>();
	}

	/**
	 * 
	 * @param className Actual FQ class name
	 * @param methodName Real method name.  eg aRealMethod
	 * @param assertionReason
	 * @param actualValueString
	 * @param matcherDescription
	 * @param wasSuccessful
	 */
    public void addAssertion(String className, String methodName, String assertionReason,
            String actualValueString, String matcherDescription, boolean wasSuccessful){
        
        ClassDetail classResult = getClassResult(className);
        
        MethodDetail methodResult = classResult.getMethodResult(methodName);
        
        AssertionDetail assertionResult = new AssertionDetail(assertionReason, actualValueString, matcherDescription, wasSuccessful);
        methodResult.addAssertion(assertionResult);
        
    }

	public Collection<ClassDetail> getClassResults() {
		return classResults.values();
	}

	private ClassDetail getClassResult(String className) {
		if (classResults.get(className) == null) {
			classResults.put(className, new ClassDetail(className));
		}

		return classResults.get(className);
	}

	public int getPassCount() {

		int passCount = 0;

		for (ClassDetail classResult : classResults.values()) {
			passCount += classResult.getPassCount();
		}

		return passCount;
	}

	public int getFailCount() {
		int failCount = 0;

		for (ClassDetail classResult : classResults.values()) {
			failCount += classResult.getFailCount();
		}

		return failCount;
	}

	public int getTotalCount() {
		int totalCount = 0;

		for (ClassDetail classResult : classResults.values()) {
			totalCount += classResult.getTotalCount();
		}

		return totalCount;
	}

}
